package com.zlc.common.core.user.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zlc.common.common.service.BaseServiceImpl;
import com.zlc.common.core.user.mapper.MayanPlatUserMapper;
import com.zlc.common.core.user.model.entity.MayanPlatUser;
import com.zlc.common.core.user.model.vo.MayanPlatUserVo;
import com.zlc.common.core.user.service.MayanPlatUserService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class MayanPlatUserServiceImpl extends BaseServiceImpl<MayanPlatUserMapper, MayanPlatUser, MayanPlatUserVo> implements MayanPlatUserService {

    @Override
    public MayanPlatUserVo queryByUserAccount(String userAccount) {
        LambdaQueryWrapper<MayanPlatUser> wrapper = wrapper();
        wrapper.eq(MayanPlatUser::getUserAccount,userAccount);
        return queryOne(wrapper);
    }

    @Override
    public List<MayanPlatUserVo> queryByUserAccounts(List<String> userAccounts) {
        if(ObjectUtil.isEmpty(userAccounts)){
            return new ArrayList<>();
        }
        LambdaQueryWrapper<MayanPlatUser> wrapper = wrapper();
        wrapper.in(MayanPlatUser::getUserAccount,userAccounts);
        return queryVoList(wrapper);
    }

    @Override
    public MayanPlatUserVo queryByUserName(String userName) {
        LambdaQueryWrapper<MayanPlatUser> wrapper = wrapper();
        wrapper.eq(MayanPlatUser::getUsername,userName);
        return queryOne(wrapper);
    }

    @Override
    public String queryUserName(String userAccount) {
        LambdaQueryWrapper<MayanPlatUser> wrapper = wrapper();
        wrapper.eq(MayanPlatUser::getUserAccount,userAccount);
        MayanPlatUserVo mayanPlatUserVo = queryOne(wrapper);
        if(ObjectUtil.isEmpty(mayanPlatUserVo)){
            return null;
        }
        return mayanPlatUserVo.getUsername();
    }
}
